import { getStorage, setStorage, removeStorage } from '/src/_util/storage.js'

export default {
	namespaced: true,
    state: {
		userInfo: getStorage('VEA_USERINFO') || null,
		rememberMe: getStorage('VEA_REMEMBERME') || 0,
		rememberAccount: getStorage('VEA_REMEMBERACCOUNT') || null,
		backPagePath: getStorage('VEA_BACKPAGEPATH') || '',
		lockStatus: getStorage('VEA_LOCKSTATUS') || 0
    },
    mutations: {
		setUserInfo (state, userInfo) {
			state.userInfo = userInfo
			setStorage('VEA_USERINFO', userInfo)
		},
		setRememberMe (state, rememberMe) {
			state.rememberMe = rememberMe
			setStorage('VEA_REMEMBERME', rememberMe)
		},
		setRememberAccount (state, rememberAccount) {
			state.rememberAccount = rememberAccount
			setStorage('VEA_REMEMBERACCOUNT', rememberAccount)
		},
		setBackPagePath (state, backPagePath) {
			state.backPagePath = backPagePath
			setStorage('VEA_BACKPAGEPATH', backPagePath)
		},
		setLockStatus (state, lockStatus) {
			state.lockStatus = lockStatus
			setStorage('VEA_LOCKSTATUS', lockStatus)
		},
		
		// 重置 store 状态数据
		resetUserStore (state) {
			state.userInfo = null
			removeStorage('VEA_USERINFO')
		}
    }
}
